// @Title api[简述该包的主要作用]
// @Description
// @Author  cnHuaShao
// @since v0.0.1
// @Version v1.0.0
// @Date 2024/5/24 22:20
// @Update 2024/5/24 22:20
package api

import (
	"FinancialManagement/src/base/baselog"
	"FinancialManagement/src/base/mess"
	"FinancialManagement/src/base/util"
	"FinancialManagement/src/business/stock"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"net/http"
)

// GetStockInList
// @Description: 获取入库信息列表
// @param c
func GetStockInList(c *gin.Context) {
	pageSize := util.ToInt(c.DefaultPostForm("pageSize", "10"))    // 显示行数
	pageNumber := util.ToInt(c.DefaultPostForm("pageNumber", "1")) // 当前页
	stockInList, count, err := stock.GetStockInList(pageSize, pageNumber)
	if err != nil {
		c.JSON(http.StatusOK, mess.ResErrMess(9005011, "获取入库列表失败"))
		return
	}
	c.JSON(http.StatusOK, mess.ResMessOK(gin.H{
		"list":  stockInList,
		"count": count,
	}))
}

// AddStockInInfo
// @Description: 添加入库信息记录
// @param c
func AddStockInInfo(c *gin.Context) {
	var stockIn stock.StockIn
	err := c.BindJSON(&stockIn)
	if err != nil {
		baselog.Logger.Error("入库信息解析时异常: ", zap.Error(err))
		c.JSON(http.StatusOK, mess.ResErrMess(9005010, "入库信息解析时异常"))
		return
	}
	stockIn.Operator = "测试人员"
	if err := stockIn.AddStockInInfo(); err != nil {
		c.JSON(http.StatusOK, mess.ResErrMess(9005012, "添加入库信息失败"))
		return
	}
	c.JSON(http.StatusOK, mess.ResMessOK(""))
}
